from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext
from django.contrib import auth
from main.models import Thumb, Gallery
from main.forms import ThumbManageForm

# Add a new thumbnail
def thumb_manage(request):
    # if request.method == 'POST':
    #     # Deal with image data
    #     form = ThumbManageForm(request.POST, request.FILES)
    #     if form.is_valid():
    #         form.save()
    #         return HttpResponseRedirect('/') # was '/thumbs'
    # else:
    #     form = ThumbManageForm()
        
    return render_to_response('thumbs.html', {'thumbs_list':Thumb.objects.all()})
                              # context_instance=RequestContext(request))

# # List all thumbnails
# def list_thumbs(request):
#     thumbs = Thumb.objects.all()
#     result_count = len(thumbs)
#     return render_to_response('thumb_list.html', locals())
    
# # Handle a request to upload an image
# def upload_image(request):
#     if request.method == 'POST':
#         form = UploadImageForm(request.POST, request.FILES)
#         if form.is_valid():
#             form.save() # This might work. Otherwise, construct manually
#             return HttpResponseRedirect('/uploaded.html')
#     else:
#         form = UploadImageForm()
#     return render_to_response('upload.html', {'form':form},
#                               context_instance=RequestContext(request))
